package template.bean.po;

import java.util.HashSet;
import java.util.Set;

public class User {

    private Integer id;

    private String username;

    private String password;

    private Set<Role> roleSet = new HashSet<>();

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Set<Role> getRoleSet() {
        return roleSet;
    }

    public void setRoleSet(Set<Role> roles) {
        this.roleSet = roles;
    }

    public Set<Permission> getPermissionSet() {
        Set<Permission> permissionSet = new HashSet<>();

        this.roleSet.forEach(role -> {
            role.getPermissionSet().forEach(permission -> {
                permissionSet.add(permission);
            });
        });

        return permissionSet;
    }


    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", roleSet.size=" + roleSet.size() +
                '}';
    }
}